<?php
/*
 * 1626cms 管理中心 企業用戶相關函數
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
*/
if (! defined ( 'IN_QISHI' )) {
	die ( 'Access Denied!' );
}
//******************************職位部分**********************************
function get_jobs_other_wage($job_id) {
	global $db;
	$sql = "select * from " . table ( 'jobs_welfare' ) . " where job_id=" . $job_id;
	$jobs_welfare_list = $db->getall ( $sql );
	return $jobs_welfare_list;
}
function get_jobs_shiftwork($job_id) {
	global $db;
	$sql = "select * from " . table ( 'jobs_shiftwork' ) . " where job_id=" . $job_id;
	$jobs_shiftwork_list = $db->getall ( $sql );
	return $jobs_shiftwork_list;
}
function del_jobs_shiftwork($job_id) {
	global $db;
	if (! $db->query ( "Delete from " . table ( 'jobs_shiftwork' ) . " WHERE job_id =" . $job_id ))
		return false;
	return true;
}
function del_jobs_welfare($job_id) {
	global $db;
	if (! $db->query ( "Delete from " . table ( 'jobs_welfare' ) . " WHERE job_id =" . $job_id ))
		return false;
	return true;
}
function del_jobs_attachment($job_id, $attachment_dir) {
	global $db;
	require_once (QISHI_ROOT_PATH . 'include/Iohandler.php');
	$iohandler = new Iohandler();
	$sql = "select * from " . table ( 'jobs_attachment' ) . " WHERE job_id =" . $job_id;
	$result = $db->query ( $sql);
	while ( $row = $db->fetch_array ( $result ) ) {
		$iohandler->DeleteFile($attachment_dir.$row ['path']);
	}
	if (! $db->query ( "Delete from " . table ( 'jobs_attachment' ) . " WHERE job_id =" . $job_id ))
		return false;
	return true;
}
function del_jobs_attachment_byuid($id, $user_id, $attachment_dir) {
	global $db;
	$sql = "select * from " . table ( 'jobs_attachment' ) . " WHERE id =" . $id. ' and user_id='.$user_id;
	$info = $db->getone ( $sql );
	if($info)
	{
		$sql = "delete from " . table ( 'jobs_attachment' ) . " WHERE id =" . $id. ' and user_id='.$user_id;
		$db->query ( $sql );
		require_once (QISHI_ROOT_PATH . 'include/Iohandler.php');
		$iohandler = new Iohandler();
		$iohandler->DeleteFile($attachment_dir.$info ['path']);
		return true;
	}
	return false;
}
function get_jobs_attachment($job_id) {
	global $db;
	$sql = "select * from " . table ( 'jobs_attachment' ) . " WHERE job_id =" . $job_id;
	return $db->getall ( $sql );
}

//獲取職位信息列表
function get_jobs($offset, $perpage, $get_sql = '') {
	global $db, $timestamp;
	$row_arr = array ();
	if (isset ( $offset ) && ! empty ( $perpage )) {
		$limit = " LIMIT " . $offset . ',' . $perpage;
	}
	$result = $db->query ( "SELECT * FROM " . table ( 'jobs' ) . " " . $get_sql . " ORDER BY id DESC " . $limit );
	while ( $row = $db->fetch_array ( $result ) ) {
		$company = get_jobs_company ( $row ['uid'] );
		$row ['companyname'] = cut_str ( $company ['companyname'], 10, 0 );
		$row ['jobs_name'] = cut_str ( $row ['jobs_name'], 7, 0 );
		$row ['company_url'] = url_rewrite ( 'company', array ('id0' => $company ['id'] ) );
		$row ['audit'] = get_jobs_audit ( $row ['audit'] );
		$row ['click'] = get_jobs_click ( $row ['id'] );
		$row ['display'] = $row ['display'] == "1" ? "正常" : "<span style=\"color:#999999\">暫停</span>";
		$row ['emergency'] = get_jobs_emergency ( $row ['emergency'] );
		$row ['jobs_url'] = url_rewrite ( 'jobs-show', array ('id0' => $row ['id'] ) );
		$row ['deadline'] = ($row ['deadline'] - $timestamp) > 0 ? date ( 'Y-m-d', $row ['deadline'] ) : "<span style=\"color:#FF6600\">已經過期</span>";
		$row_arr [] = $row;
	}
	return $row_arr;
}
//獲取單條職位
function get_jobs_one($id = 0) {
	global $db, $timestamp;
	if (intval ( $id ) != $id)
		return false;
	$sql = "select * from " . table ( 'jobs' ) . " where id=" . $id;
	$val = $db->getone ( $sql );
	$company = get_jobs_company ( $val ['uid'] );
	$val ['companyname'] = $company ['companyname'];
	$val ['company_url'] = url_rewrite ( 'company', array ('id0' => $company ['id'] ) );
	$val ['jobs_username'] = get_username ( $val ['uid'] );
	$val ['contents'] = get_jobs_contents ( $id );
	$val ['contact'] = get_jobs_contact ( $id );
	$val ['deadline_days'] = ($val ['deadline'] - $timestamp) > 0 ? "距離截止時間還有<strong style=\"color:#FF0000\">" . sub_day ( $val ['deadline'], $timestamp ) . "</strong>" : "<span style=\"color:#FF6600\">目前已經過期</span>";
	return $val;
}
//獲取職位描述
function get_jobs_contents($id) {
	global $db;
	if (intval ( $id ) != $id)
		return false;
	$sql = "select * from " . table ( 'jobs_contents' ) . " where pid=" . $id;
	$val = $db->getone ( $sql );
	return $val ['contents'];
}
//獲取職位聯系方式
function get_jobs_contact($id) {
	global $db;
	if (intval ( $id ) != $id)
		return false;
	$sql = "select * from " . table ( 'jobs_contact' ) . " where pid=" . $id;
	$val = $db->getone ( $sql );
	return $val;
}
//從UID下的所有職位，返回array
function get_jobs_inuid($uid) {
	global $db;
	if (intval ( $uid ) != $uid)
		return false;
	$sql = "select * from " . table ( 'jobs' ) . " WHERE uid='" . $uid . "' ORDER BY id asc";
	$info = $db->getall ( $sql );
	return $info;
}
//刪除職位
function del_jobs($del_id) {
	global $db;
	if (is_array ( $del_id )) {
		$sqlin = implode ( ",", $del_id );
		if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs' ) . " WHERE id IN (" . $sqlin . ")" ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_contact' ) . " WHERE pid IN (" . $sqlin . ") " ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_contents' ) . " WHERE pid IN (" . $sqlin . ") " ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_click' ) . " WHERE pid IN (" . $sqlin . ") " ))
			return false;
		return true;
	}
	if (intval ( $del_id ) == $del_id && ! is_array ( $del_id )) {
		if (! $db->query ( "Delete from " . table ( 'jobs' ) . " WHERE id='" . $del_id . "'" ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_contact' ) . " WHERE pid='" . $del_id . "'" ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_contents' ) . " WHERE pid='" . $del_id . "'" ))
			return false;
		if (! $db->query ( "Delete from " . table ( 'jobs_click' ) . " WHERE pid='" . $del_id . "'" ))
			return false;
		return true;
	}
	return false;
}
//修改職位審核狀態
function edit_jobs_audit($id, $audit) {
	global $db, $_CFG;
	if (! is_numeric ( $audit ) || $audit + 0 == 0)
		return false;
	if (is_array ( $id )) {
		$sqlin = implode ( ",", $id );
		if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
			return false;
		if (! $db->query ( "update  " . table ( 'jobs' ) . " SET audit='" . $audit . "'  WHERE id IN (" . $sqlin . ")" ))
			return false;
		
		//發送郵件
		$mailconfig = get_cache ( 'mailconfig' ); //獲取郵件規則
		if ($audit == "1" && $mailconfig ['set_jobsallow'] == "1") //審核通過
{
			$result = $db->query ( "SELECT * FROM " . table ( 'jobs' ) . " WHERE id IN (" . $sqlin . ")  GROUP BY uid " );
			while ( $list = $db->fetch_array ( $result ) ) {
				require_once ('../PHPMailer/class.phpmailer.php');
				asyn_sendmail ( $_CFG ['site_domain'] . $_CFG ['site_dir'] . "asyn_mail.php?uid=" . $list ['uid'] . "&key=" . asyn_userkey ( $list ['uid'] ) . "&act=set_jobsallow" );
			}
		}
		if ($audit == "3" && $mailconfig ['set_jobsnotallow'] == "1") //審核未通過
{
			$result = $db->query ( "SELECT * FROM " . table ( 'jobs' ) . " WHERE id IN (" . $sqlin . ")  GROUP BY uid " );
			while ( $list = $db->fetch_array ( $result ) ) {
				require_once ('../PHPMailer/class.phpmailer.php');
				asyn_sendmail ( $_CFG ['site_domain'] . $_CFG ['site_dir'] . "asyn_mail.php?uid=" . $list ['uid'] . "&key=" . asyn_userkey ( $list ['uid'] ) . "&act=set_jobsnotallow" );
			}
		}
		//發送郵件
		return true;
	}
	return false;
}
//獲取職位審核狀態
function get_jobs_audit($audit) {
	switch ($audit) {
		case 1 :
			$audit = "審核通過";
			break;
		case 2 :
			$audit = "審核中···";
			break;
		case 3 :
			$audit = "<span style=\"color:#999999\">審核未通過</span>";
			break;
		default :
			$audit = "未知";
	}
	return $audit;
}
//修改職位屬性（普通，招聘）
function edit_jobs_emergency($id, $emergency) {
	global $db;
	if (is_array ( $id )) {
		$sqlin = implode ( ",", $id );
		if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
			return false;
		if (! $db->query ( "update  " . table ( 'jobs' ) . " SET emergency='" . intval ( $emergency ) . "'  WHERE id IN (" . $sqlin . ")" ))
			return false;
		return true;
	}
	return false;
}
//獲取職位屬性：普通,緊急
function get_jobs_emergency($emergency) {
	switch ($emergency) {
		case 1 :
			$emergency = "普通";
			break;
		case 2 :
			$emergency = "<span style=\"color:#FF6600\">緊急</span>";
			break;
		default :
			$emergency = "未知";
	}
	return $emergency;
}
//獲取職位所屬公司
function get_jobs_company($uid) {
	global $db;
	$sql = "select * from " . table ( 'company_profile' ) . " where uid=" . $uid;
	$val = $db->getone ( $sql );
	return $val;
}
//獲取所屬會員
function get_username($uid) {
	global $db;
	$sql = "select * from " . table ( 'members' ) . " where uid=" . $uid;
	$val = $db->getone ( $sql );
	return $val ['username'];
}
//獲取職位點擊次數
function get_jobs_click($pid) {
	global $db;
	$sql = "select * from " . table ( 'jobs_click' ) . " where pid=" . $pid;
	$val = $db->getone ( $sql );
	return $val ['click'];
}
//******************************企業部分**********************************
//獲取企業列表
function get_company_profile($offset, $perpage, $get_sql = '') {
	global $db;
	$row_arr = array ();
	if (isset ( $offset ) && ! empty ( $perpage )) {
		$limit = " LIMIT " . $offset . ',' . $perpage;
	}
	$result = $db->query ( "SELECT * FROM " . table ( 'company_profile' ) . " " . $get_sql . " ORDER BY id DESC " . $limit );
	while ( $row = $db->fetch_array ( $result ) ) {
		$row ['companyname'] = $row ['company_name_cn']? cut_str ( $row ['company_name_cn'], 10, 0 ): cut_str ( $row ['company_name_en'], 10, 0 );
		$row ['company_url'] = url_rewrite ( 'company', array ('id0' => $row ['id'] ) );
		$row ['audit'] = get_company_audit ( $row ['audit'] );
		$row ['user'] = get_user ( $row ['uid'] );
		$row ['points'] = get_user_points ( $row ['uid'] );
		$row_arr [] = $row;
	}
	return $row_arr;
}
//獲取單條企業資料
function get_company_profile_one($id = 0) {
	global $db;
	if (intval ( $id ) != $id)
		return false;
	$sql = "select * from " . table ( 'company_profile' ) . " where id=" . $id;
	$val = $db->getone ( $sql );
	$val ['user'] = get_user ( $val ['uid'] );
	return $val;
}
//獲取單條企業資料
function get_company_profile_one_byuid($uid = 0) {
	global $db;
	if (intval ( $uid ) != $uid)
		return false;
	$sql = "select * from " . table ( 'company_profile' ) . " where uid=" . $uid;
	$val = $db->getone ( $sql );
	$val ['user'] = get_user ( $val ['uid'] );
	return $val;
}
//獲取企業介紹
function get_company_profile_contents($uid) {
	global $db;
	$sql = "select * from " . table ( 'company_profile_contents' ) . " where uid=" . $uid;
	$lsit = $db->getone ( $sql );
	return $lsit;
}
//獲取企業認證狀態
function get_company_audit($audit) {
	switch ($audit) {
		case '0' :
			$audit = "未認證";
			break;
		case 1 :
			$audit = "認證通過";
			break;
		case 2 :
			$audit = "<span style=\"color:#FF6600\">等待認證</span>";
			break;
		case 3 :
			$audit = "<span style=\"color:#666666\">認證未通過</span>";
			break;
		default :
			$audit = "未知";
	}
	return $audit;
}
//更改企業認證狀態
function edit_company_audit($uid, $audit) {
	global $db, $_CFG;
	if (! is_numeric ( $audit ) || ! intval ( $audit ))
		return false;
	if (! is_array ( $uid ))
		return false;
	$sqlin = implode ( ",", $uid );
	if (! is_numeric ( str_replace ( ",", "", $sqlin ) ) || ! intval ( str_replace ( ",", "", $sqlin ) ))
		return false;
	if (! $db->query ( "update  " . table ( 'company_profile' ) . " SET audit='" . $audit . "'  WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if ($audit == "1") {
		$points_rule = get_cache ( 'members_points_rule' );
		if ($points_rule ['company_auth'] > 0) { //如果設置了認證贈送積分
			if (! gift_points ( $sqlin, $points_rule ['company_auth'] ))
				return false; //贈送
		}
	}
	//發送郵件
	$mailconfig = get_cache ( 'mailconfig' ); //獲取郵件規則
	if ($audit == "1" && $mailconfig ['set_licenseallow'] == "1") //認證通過
{
		$result = $db->query ( "SELECT * FROM " . table ( 'company_profile' ) . " WHERE uid IN (" . $sqlin . ")" );
		while ( $list = $db->fetch_array ( $result ) ) {
			require_once ('../PHPMailer/class.phpmailer.php');
			asyn_sendmail ( $_CFG ['site_domain'] . $_CFG ['site_dir'] . "asyn_mail.php?uid=" . $list ['uid'] . "&key=" . asyn_userkey ( $list ['uid'] ) . "&act=set_licenseallow" );
		}
	}
	if ($audit == "3" && $mailconfig ['set_licensenotallow'] == "1") //認證未通過
{
		$result = $db->query ( "SELECT * FROM " . table ( 'company_profile' ) . " WHERE uid IN (" . $sqlin . ")" );
		while ( $list = $db->fetch_array ( $result ) ) {
			require_once ('../PHPMailer/class.phpmailer.php');
			asyn_sendmail ( $_CFG ['site_domain'] . $_CFG ['site_dir'] . "asyn_mail.php?uid=" . $list ['uid'] . "&key=" . asyn_userkey ( $list ['uid'] ) . "&act=set_licensenotallow" );
		}
	}
	//發送郵件
	return true;
}
//更改企業推薦狀態
function edit_company_recommend($uid, $recommend) {
	global $db;
	if (! is_array ( $uid ))
		return false;
	$sqlin = implode ( ",", $uid );
	if (! is_numeric ( str_replace ( ",", "", $sqlin ) ) || ! intval ( str_replace ( ",", "", $sqlin ) ))
		return false;
	if (! $db->query ( "update  " . table ( 'company_profile' ) . " SET recommend='" . intval ( $recommend ) . "'  WHERE uid IN (" . $sqlin . ")" ))
		return false;
	return true;
}
//企業認證通過后贈送積分
function gift_points($uid, $points) {
	global $db;
	if (! is_numeric ( str_replace ( ",", "", $uid ) ) || ! intval ( str_replace ( ",", "", $uid ) ))
		return false;
	$row_arr = array ();
	$result = $db->query ( "SELECT uid FROM " . table ( 'company_profile' ) . " WHERE uid IN (" . $uid . ") AND audit='1' AND awards_points= '1'" );
	while ( $row = $db->fetch_array ( $result ) ) {
		if (! report_deal ( $row ['uid'], 1, $points, "<span style=\"color:#33CC00\">成為已認證企業系統贈送！</span>" ))
			return false;
		$sql = "UPDATE " . table ( 'company_profile' ) . " SET awards_points= '2' WHERE uid='" . $row ['uid'] . "'"; //設為已經贈送過
		if (! $db->query ( $sql ))
			return false;
	}
	return true;
}
//刪除企業資料，uid=array
function del_company($d_uid) {
	global $db, $certificate_dir;
	if (! is_array ( $d_uid ))
		return false;
	$sqlin = implode ( ",", $d_uid );
	if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
		return false;
	$result = $db->query ( "SELECT * FROM " . table ( 'company_profile' ) . " WHERE uid IN (" . $sqlin . ")" ); //先刪除企業營業執照
	while ( $row = $db->fetch_array ( $result ) ) {
		@unlink ( $certificate_dir . $row ['certificate_img'] );
	}
	if (! $db->query ( "Delete from " . table ( 'company_profile' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'company_profile_contents' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	return true;
}
//刪除此企業發布的所有職位，d_uid=array
function del_company_alljobs($d_uid) {
	global $db;
	if (! is_array ( $d_uid ))
		return false;
	$sqlin = implode ( ",", $d_uid );
	if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
		return false;
	foreach ( $d_uid as $u_info ) {
		$us_info_arr = get_jobs_inuid ( $u_info );
		for($i = 0; $i < count ( $us_info_arr ); $i ++) {
			if (! del_jobs ( $us_info_arr [$i] ['id'] ))
				return false;
		}
		$us_info_arr = '';
	}
	return true;
}
//******************************會員充值部分**********************************
//獲取會員充值記錄列表
function get_pay_list($offset, $perpage, $get_sql = '') {
	global $db;
	$row_arr = array ();
	if (isset ( $offset ) && ! empty ( $perpage )) {
		$limit = " LIMIT " . $offset . ',' . $perpage;
	}
	$result = $db->query ( "SELECT * FROM " . table ( 'payment_log' ) . " " . $get_sql . " ORDER BY id DESC " . $limit );
	while ( $row = $db->fetch_array ( $result ) ) {
		$row ['user'] = get_user ( $row ['uid'] );
		$row ['payment_name'] = get_payment_info ( $row ['payment_name'], true );
		$row_arr [] = $row;
	}
	return $row_arr;
}
//獲取單條充值記錄
function get_pay_one($id = 0) {
	global $db;
	if (intval ( $id ) != $id)
		return false;
	$sql = "select * from " . table ( 'payment_log' ) . " where id=" . $id;
	$val = $db->getone ( $sql );
	$val ['payment_name'] = get_payment_info ( $val ['payment_name'], true );
	$val ['payment_username'] = get_username ( $val ['uid'] );
	return $val;
}
//取消充值記錄
function del_payment($id) {
	global $db;
	if (! intval ( $id ) || ! is_numeric ( $id ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'payment_log' ) . " WHERE id='" . $id . "'  AND is_paid='1'" ))
		return false;
	return true;
}
//獲取充值支付方式名稱
function get_payment_info($typename, $name = false) {
	global $db;
	$sql = "select * from " . table ( 'payment' ) . " where typename ='" . $typename . "'";
	$val = $db->getone ( $sql );
	if ($name) {
		return $val ['byname'];
	} else {
		return $val;
	}
}
//******************************企業會員部分**********************************
//企業會員列表
function get_member_list($offset, $perpage, $get_sql = '') {
	global $db;
	$row_arr = array ();
	if (isset ( $offset ) && ! empty ( $perpage )) {
		$limit = " LIMIT " . $offset . ',' . $perpage;
	}
	$result = $db->query ( "SELECT * FROM " . table ( 'members' ) . " " . $get_sql . $limit );
	while ( $row = $db->fetch_array ( $result ) ) {
		$row ['points'] = get_user_points ( $row ['uid'] );
		$company = get_jobs_company ( $row ['uid'] );
		$row ['company_name'] = $company ['company_name_cn']?$company ['company_name_cn']: $company ['company_name_en'];
		$row ['company_url'] = url_rewrite ( 'company', array ('id0' => $company ['id'] ) );
		$row_arr [] = $row;
	}
	return $row_arr;
}
//刪除企業會員
function delete_company_user($uid) {
	global $db;
	if (! is_array ( $uid ))
		return false;
	$sqlin = implode ( ",", $uid );
	if (! is_numeric ( str_replace ( ",", "", $sqlin ) ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'members' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'members_type' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'members_points' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'members_points_report' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	if (! $db->query ( "Delete from " . table ( 'payment_log' ) . " WHERE uid IN (" . $sqlin . ")" ))
		return false;
	return true;
}
//生成會員秘匙，防止異步數據外部提交
function asyn_userkey($uid) {
	$user = get_user ( intval ( $uid ) );
	$key = md5 ( $user ['username'] . $user ['pwd_hash'] . $user ['password'] );
	return $key;
}
//******************************其他**********************************
//獲取會員信息，返回用戶名等相關信息
function get_user($uid) {
	global $db;
	$sql = "select * from " . table ( 'members' ) . " where uid = '$uid'";
	$user_info = $db->getone ( $sql );
	return $user_info;
}
//獲取會員積分總數
function get_user_points($uid) {
	global $db;
	$sql = "select * from " . table ( 'members_points' ) . " where uid = '$uid'";
	$points = $db->getone ( $sql );
	return $points ['points'];
}
//獲取積分規則
function get_points_rule() {
	global $db;
	$sql = "select * from " . table ( 'members_points_rule' ) . "  ORDER BY id asc";
	$list = $db->getall ( $sql );
	return $list;
}
//-------------------------------------------------------
//執行充值
function order_paid($v_oid) {
	global $db, $timestamp, $_CFG;
	$sql = "UPDATE " . table ( 'payment_log' ) . " SET is_paid= '2',payment_time='" . $timestamp . "' WHERE oid='$v_oid'";
	if (! $db->query ( $sql ))
		return false;
	$sqls = "select * from " . table ( 'payment_log' ) . " WHERE oid ='$v_oid'";
	$list = $db->getone ( $sqls );
	$notes = date ( 'Y-m-d H:i', time () ) . "通過：" . get_payment_info ( $list ['payment_name'], true ) . " 成功充值 " . $list ['amount'] . "元";
	if (! report_deal ( $list ['uid'], 1, $list ['points'], $notes ))
		return false;
	
		//發送郵件
	$mailconfig = get_cache ( 'mailconfig' );
	if ($mailconfig ['set_payment'] == "1") {
		require_once ('../PHPMailer/class.phpmailer.php');
		asyn_sendmail ( $_CFG ['site_domain'] . $_CFG ['site_dir'] . "asyn_mail.php?uid=" . $list ['uid'] . "&key=" . asyn_userkey ( $list ['uid'] ) . "&act=set_payment" );
	}
	//發送郵件完畢
	return true;
}
/* 
積分操作 
$uid:會員ID
$i_type：1：增加積分。2扣除積分
$points:積分
$notes:備注
*/
function report_deal($uid, $i_type = 1, $points = 0, $notes) {
	global $db, $timestamp;
	$points_val = get_user_points ( $uid );
	if ($i_type == 1) {
		$points_val = $points_val + $points;
	}
	if ($i_type == 2) {
		$points_val = $points_val - $points;
		$points_val = $points_val < 0 ? 0 : $points_val;
	}
	$sql = "INSERT INTO " . table ( 'members_points_report' ) . " (uid,i_type,points,remain_points,addtime,notes) VALUES ('$uid','$i_type','$points','$points_val', '$timestamp', '$notes')";
	! $db->query ( $sql ) ? showmsg ( '未知錯誤！', 0 ) : '';
	$sql = "UPDATE " . table ( 'members_points' ) . " SET points= '$points_val' WHERE uid='$uid'";
	! $db->query ( $sql ) ? showmsg ( '未知錯誤！', 0 ) : '';
	return true;
}
?>
